package codegen.groovy.graphnetwork.graphics

import groovy.swing.j2d.GraphicsBuilder
import javax.swing.JComponent;
import codegen.graphnetwork.model.*
/** 
*The place holder Graph implementation for testing 
*replace by JUNG
*/
public class LinkDisplay{
    def Link l
    def gb = new GraphicsBuilder()
    def parent;
    LinkDisplay(Link l){
        this.l= l
        
    }
    
    public def getLinkShape(){
        def sn=NodeDisplay.getNodeSize(l.start)
        def en=NodeDisplay.getNodeSize(l.end)
        /*
        def sp=[x:sn.x+sn.w/2,y:sn.y+sn.h/2]
        def ep=[x:en.x+en.w/2,y:en.y+en.h/2]
         */
        def sv=NodeDisplay.getValueSize(l.input)
        def ev=NodeDisplay.getValueSize(l.output)
           
        def sp=[x:sn.x+sv.x,y:sn.y+sv.y]
        def ep=[x:en.x+ev.x,y:en.y+ev.y]
        
        
        //def ctrl1=[x:(sp.x+ep.x)/2,y:sp.y]
        //def ctrl2=[x:ep.x,y:(sp.y+ep.y)/2]
        
        def ctrl1= (sp.x<ep.x)?[x:ep.x-20,y:sp.y]:[x:sp.x+60,y:sp.y]
        def ctrl2=(sp.x<ep.x)?[x:sp.x+20,y:ep.y]:[x:ep.x-60,y:sp.y]   
        
        def go = gb.group {
            cubicCurve( x1: sp.x, y1: sp.y, ctrlx1: ctrl1.x, ctrly1: ctrl1.y, ctrlx2: ctrl2.x, ctrly2: ctrl2.y, x2: ep.x, y2: ep.y,
                borderColor: 'blue', borderWidth: 2 )
        }
        
        return go
    }
}
